package com.longxi.tianjintianbao.ui.adapter.multitype.message;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.AdapterListener;
import com.longxi.tianjintianbao.model.message.MessageList;
import com.longxi.tianjintianbao.model.message.MessagePush;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class MessageListViewBinder extends ItemViewBinder<MessageList, MessageListViewBinder.ViewHolder> {

    private AdapterListener listener;
    private String title;

    public MessageListViewBinder(AdapterListener listener, String title) {
        this.listener = listener;
        this.title = title;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_message_push, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull MessageList messageList) {
        holder.mTvTip.setText(title);
        holder.mTvContent.setText(messageList.getMessagecontent());

        holder.mTvLookDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(holder.getAdapterPosition());
            }
        });

        if(messageList.getLookover() == 0){
            holder.mTvDate.setText("未读");
        }else{
            holder.mTvDate.setText("");
            holder.mTvDate.setHint("已读");
        }

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(holder.getAdapterPosition());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout mLlBtn;
        TextView mTvTip;
        TextView mTvDate;
        TextView mTvContent;
        TextView mTvLookDetail;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvTip = itemView.findViewById(R.id.tvTip);
            mTvDate = itemView.findViewById(R.id.tvDate);
            mTvContent = itemView.findViewById(R.id.tvContent);
            mTvLookDetail = itemView.findViewById(R.id.tvLookDetail);
        }
    }
}
